<?=View::factory('admin/common/header')?>
<div id="content">
  <div class="breadcrumb">
    <a href="<?=URL::site('admin')?>">管理首页</a>
    &raquo; <a href="<?=URL::site('admin/manager_role')?>">管理员角色</a>
    &raquo; 权限指派
  </div>
  <?=View::factory('admin/common/message')?>
  <div class="box">
    <div class="heading">
      <h1><img src="<?=URL::site()?>images/admin/user-group.png" alt="" /> 权限指派</h1>
      <div class="buttons">
        <input type="button" onclick="$('#form').ajax_post({redirect:'<?=URL::site('admin/manager_role')?>'});" class="btn45" value="保存" /> &nbsp;
        <input type="button" onclick="history.back();" class="btn45" value="返回" />
      </div>
    </div>
    <div class="content">
      <form method="post" enctype="multipart/form-data" id="form" onsubmit="return $('#form').ajax_post({redirect:'<?=URL::site('admin/manager_role')?>'});">
        <table class="form">
          <? foreach ($privileges as $res_name => $items) { ?>
          <tr>
            <td width="120"><label><input type="checkbox" class="_checkAll" /> <strong><?=$res_name; ?></strong></label></td>
            <td>
            <? foreach ($items as $priv) { ?>
            <label style="display: block; width: 16.6%; float: left; height: 24px; line-height: 24px;">
              <input type="checkbox" name="rules[]" class="rules" value="<?=$priv['priv_id']?>" <?=in_array($priv['priv_id'], $rules)?'checked':''?> /> <?=$priv['priv_name']; ?>
            </label>
            <? } ?></td>
          </tr>
          <? }?>
          <tr>
            <td><label><input type="checkbox" class="checkAll" /> <strong>全部选中</strong></label></td>
            <td>&nbsp;</td>
          </tr>
        </table>
      </form>
    </div>
</div>
<?=View::factory('admin/common/footer')?>
<script type="text/javascript">
$().ready(function(){
    $('.checkAll:checkbox').click(function(){
        $(this).parent().parent().parent().prevAll().find(':checkbox').attr('checked', this.checked);
    });
    $('._checkAll:checkbox').click(function(){
        $(this).parent().parent().next().find(':checkbox').attr('checked', this.checked);
        if (!this.checked) {
            $('.checkAll:checkbox').attr('checked', false);
        }
    });
    $('.rules:checkbox').click(function(){
        if (!this.checked) {
            $('.checkAll:checkbox').attr('checked', false);
            $(this).parent().parent().prev().find(':checkbox').attr('checked', false);
        }
    });
    $('#system').addClass('selected');
});
</script>